home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 April: Mac OS SDK / Dev.CD Apr 97 SDK1.toast / Development Kits (Disc 1) / Installer SDK Cornucopia 1.0.2 / Script Examples / File Compare by Procedure / myCompareProc.r < prev    next >
Encoding:
Text File  |  1996-09-30  |  8.0 KB  |  213 lines  |  [TEXT/MPS ]

  1. //
  2. //    myCompareProc.r
  3. //
  4. //        This example installs a copy of the "ReadMe" file to the folder
  5. //        'Compare Proc Example:' at the root of the selected target volume.
  6. //        Since the same file will be being installed over itself on repeated
  7. //        installations, it will not be possible to see the effects of the
  8. //        file version comparison unless you modify the 'vers' (1) or (2) resource
  9. //        item of the installed file to a higher version, and then save the
  10. //        modified file to the same location. Then on the next installation
  11. //        a dialog will be displayed asking the user "Newer, Older, Cancel".
  12. //        Note that during Easy Install, a newer file will simply not
  13. //        be replaced, while under Custom Install a dialog with choices
  14. //        is presented to the user.
  15. //
  16. //        This example script uses a custom version compare procedure to
  17. //        check whether a target file about to be replaced is older, newer,
  18. //        or the same version as the file that is about to replace it.
  19. //
  20. //        A custom version procedure is a code resource, compiled from a
  21. //        seperate source file ( ours is written in C ). That code is linked
  22. //        to a file by declaring an 'invc' resource within the Installer
  23. //        script, that is then referenced from within a file atom ( 'infa' ). 
  24. //
  25. //        A custom version procedure simply returns the version number 
  26. //        of the target file based on whatever method the scriptwriter 
  27. //        feels is appropriate. A more appropriate name might have been
  28. //        custom Get Version procedure, since the version compare procedure 
  29. //        does not actually perform the comparison between files.
  30. //    
  31. //        The Installer will use that returned version number to perform
  32. //        it's usual version comparison. No further action is needed from
  33. //        the custom version compare procedure, once it has returned the
  34. //        version number of the file. 
  35. //
  36. //        The Installer will handle setting up the file for the custom version 
  37. //        compare procedure. There is no need to open the file or the file's 
  38. //        resource fork from within the version compare procedure. The resource
  39. //        items can be read immediately from within the custom version procedure.
  40. //    
  41. //        Our custom version procedure returns the version number found
  42. //        in the target file's 'vers' (1) resource. If no 'vers' (1)
  43. //        resource item is found in the target file, then the custom version
  44. //        proc will return the 'vers' (2) of the target file. If neither
  45. //        the 'vers' (1) or 'vers' (2) resource is found, then the custom
  46. //        version compare procedure returns 0.
  47. //    
  48. //        This, by the way, is what the Installer normally does anyway, so
  49. //        our custom version procedure isn't really all that valuable in it's
  50. //        present form. You may customize the source code for the provided
  51. //        custom version compare procedure to return the version number of a
  52. //        file as is appropriate for your project needs.
  53. //
  54. //        You must specify the flags 'useVersProcToCompare' for the custom
  55. //        version procedure to be called from within a file atom ( 'infa' ).
  56. //        You will most likely also want to set the flag 'leaveAloneIfNewer'
  57. //        within your file atom, so that a newer file will not be replaced
  58. //        when installing from Easy Install, and that a dialog asking the
  59. //        user to choose "newer, older, cancel" is provided to the user
  60. //        when a newer target file is encountered during a Custom Install.
  61. //
  62. //        IMPORTANT: You must either manaully set the source version number 
  63. //        within the file atom ( 'infa' ) or create a ScriptCheck extension that
  64. //        computes the value during ScriptChecking process.  See the 
  65. //        ScriptCheck User's Guide for more information on writing ScriptCheck
  66. //        extensions.
  67. //
  68. //        You must also create a resource of type 'invc' that specifies the
  69. //        resource type and resource ID of the code resource item containing
  70. //        the custom version procedure. These values are established within
  71. //        the compile ( C ) line of the makefile provided for creating the
  72. //        custom version compare procedure.
  73. //
  74. //
  75. //        Copyright 1993-1996, Apple Computer, Inc., All Rights Reserved
  76. //
  77.  
  78. #include "InstallerTypes.r"
  79.  
  80. // include the file containing custom version compare procedure code resource item
  81. // - note that since this external file is in the form of a file containing
  82. // already compiled resources, that the include line does not use '#include' 
  83. // and that it is terminated with a semicolon.
  84. include "GetFileVersion.rsrc";
  85.  
  86. resource 'inpk' (100) {
  87.     format0 {
  88.         showsOnCustom,
  89.         removable,
  90.         dontForceRestart,
  91.         0,
  92.         0,
  93.         "ReadMe to “Compare Proc Example” folder.",
  94.         {    
  95.         'infa', 1000    // file atom using the version compare procedure
  96.         },
  97.     }
  98. };
  99.  
  100. resource 'infa' (1000) {
  101.     format1 {
  102.         deleteWhenRemoving,
  103.         deleteWhenInstalling,
  104.         copy,                            
  105.         dontIgnoreLockedFile,
  106.         dontSetFileLocked,
  107.         useVersProcToCompare,            //  • Use vers proc
  108.         srcNeedNotExist,
  109.         rsrcForkInRsrcFork,
  110.         leaveAloneIfNewer,                //  • Do not update a newer file
  111.         updateExisting,                    
  112.         copyIfNewOrUpdate,
  113.         rsrcFork,
  114.         dataFork,
  115.         0,
  116.         0x0,
  117.         10000,                            // target file spec
  118.         {    
  119.             20000,                         // source file spec
  120.             0, 
  121.             0    
  122.         },
  123.         
  124.         0x04038000,            //  4.0.3 • The source version number in BCD format 
  125.                             //    This version number will be used by the version
  126.                             //     proc specified below to determine whether or not
  127.                             //  existing target file, if any, should be replaced.
  128.                             
  129.                             // HINT FOR CREATING THIS VALUE - if you'd like an
  130.                             // easy way to determine this hex value, in ResEdit 
  131.                             // open any file with a version visible from GetInfo .
  132.                             // Double click to open a 'vers' resource and note 
  133.                             // the version displayed. Then open the same 'vers'
  134.                             // resource with the ResEdit menu item
  135.                             // "Resource/Open using Hex editor" ( you must have
  136.                             // a resource item selected ). The first eight digits
  137.                             // in the center column are the binary coded decimal
  138.                             // form of the 'vers' resource item.
  139.                             
  140.                             
  141.         128,                //  • 'invc' rsrc ID for custom version proc
  142.                         
  143.         0,
  144.         "Example File"
  145.         }
  146.     };
  147.  
  148. resource 'invc' ( 128 ) {
  149.     format0 {
  150.         'infn',                //  The resource type of the actual custom proc
  151.         128,                //  The resource id of the actual custom proc
  152.                             // NOTE: The code resource type and ID
  153.                             // values are specified within the makefile 
  154.                             // for the compare proc code resource. 
  155.                             // In this example the lines that create the 
  156.                             // compare proc code resource are in the same 
  157.                             // makefile as the one that builds the Installer 
  158.                             // script. You should use the values specified 
  159.                             // in the makefile to fill in these fields.
  160.         
  161.         0,                    //  The minimum amount of memory needed by the proc
  162.                             //    NOTE: A value of 0 specifies that the Installer's
  163.                             //     allocated memory will be used by the version
  164.                             //     compare code resource. Unless your code resource
  165.                             //     has a specific need for its own memory heap you
  166.                             //    should always assign this field a value of 0.
  167.                             
  168.         "Returns vers 1 or vers 2 version number.",
  169.         }
  170.     };
  171.  
  172. // target file spec for ReadMe file
  173. resource 'intf' (10000) {
  174.     format1 {
  175.         noSearchForFile,                 // use default search path
  176.         
  177.         TypeCrMustMatch,                 // If this is set to TypeCrMustMatch
  178.                                         // then a file with a different type
  179.                                         // and creator than those specified
  180.                                         // below will not be replaced.
  181.                                         // If this is set to TypeCrNeedNotMatch
  182.                                         // then type and creator of an existing
  183.                                         // target file are ignored.
  184.         
  185.         // The Type and Creator fields will be used to set the
  186.         // file's Type and Creator when a new file is created. 
  187.         'ttro',                         // TYPE for new file
  188.         'ttxt',                         // CREATOR for new file
  189.         
  190.         0,                                 // finder attribute flags
  191.                                         // filled by ScriptCheck is value is 0
  192.         
  193.         1,                                  // creation date for new file
  194.         1,                                  // modification date for new file
  195.                                         // NOTE: DATE values are filled
  196.                                         // by ScriptCheck if the value is 1
  197.                                             
  198.         0,                                 // search proc ID ( 'insp' ), none used
  199.         
  200.         ":Compare Proc Example:Example File"    // path to target file
  201.         }
  202.     };
  203.  
  204. // source file spec for Example File file
  205. resource 'infs' (20000) {
  206.     'ttro',
  207.     'ttxt',
  208.     0x1,
  209.     noSearchForFile,
  210.     TypeCrMustMatch,
  211.     "Disk1:Example File"                        // path to source file
  212.     };
  213.